package entity

import (
	"gitee.com/bupt-zkjc/fabric2.2-interface/model"
	"strings"
)
type Nodes struct {
	Orderers    []*Orderer  `json:"orderers"`
	Peers       []*Peer     `json:"peers"`
}
func ParseFabircChainAndChannel(chain Chain, channel Channel) model.FabricChain {
	fc := model.FabricChain{
		ChainName : chain.Name,
		OrdererName: channel.OrdererName,
		PeersOrgs : strings.Split(channel.Orgs, ","),
		ChannelName : channel.ChannelName,
		WorkPath : chain.WorkPath,
		ChannelPath : chain.ChannelPath,
		CryptoPath : chain.CryptoPath,
 		ChaincodeSourcePath : chain.ChaincodeSourcePath,
	}

	return fc
}


func ParseFabircChannel(chain model.FabricChain, cc Chaincode) model.FabricChannel {
	fc := model.FabricChannel{
		FabricChain : chain,
		ChaincodeName : cc.ChaincodeName,
		Version : cc.Version,
		Policy : cc.Policy,
		GithubPath : cc.GithubPath,
	}
	return fc
}

func ParseFabircChannelAndChaincodeWithOrg(channel model.FabricChannelWithOrg, cc Chaincode) model.FabricChannelAndChaincodeWithOrg {
	fc := model.FabricChannelAndChaincodeWithOrg{
		FabricChannelWithOrg : channel,
		ChaincodeName : cc.ChaincodeName,
		Version : cc.Version,
		Language: cc.Language,
		Policy : cc.Policy,
		GithubPath : cc.GithubPath,
	}
	return fc
}
//
func ParseFabircChannelWithOrg(chain Chain, channel Channel) model.FabricChannelWithOrg {
	fc := model.FabricChannelWithOrg{
		ChainName : chain.Name,
		OrdererName: channel.OrdererName,
		PeersOrgs : strings.Split(channel.Orgs, ","),
		OrgPeers:   strings.Split(channel.Peers, ","),
		EndorserOrgs: strings.Split(channel.EndorserOrgs, ","),
		ApprovePeers: strings.Split(channel.ApprovePeers, ","),
		EndorserPeers: strings.Split(channel.EndorserPeers, ","),
		ChannelName : channel.ChannelName,
		WorkPath : chain.WorkPath,
		ChannelPath : chain.ChannelPath,
		CryptoPath : chain.CryptoPath,
		ChaincodeSourcePath : chain.ChaincodeSourcePath,
	}
	return fc
}
